#登录验证
def login(username, passwd):
    if username == "sctl" and passwd == "123456":
        print("欢迎进入三乐购物系统！")
        return True
    else:
        return False

#进入系统之后输入购物预算信息
def Budget(budget):
    print("您的购物预算为:", budget)

#查看商品信息
def checkProduct():
    print("商品信息:")
    for product_id, product in products.items():
        print(f'商品编号:{product_id}, 商品：{product["name"] }, 价格:{product["price"]}')


#查看已购买信息
def viewPurchased():
    # print("已购买商品:")
    for i in purchased:
        print(f"您已购买的商品:{i['name']}, 价格:{i['price']}")


#购买商品
purchased = []
def buy_product(product_id, budget):
    global purchased
    if product_id in products:
        product = products[product_id]
        if budget >= product['price']:
            budget -= product['price']
            purchased.append(product)
            print(f"购买成功，已购买商品:{product['name']}, 您的余额为{budget}。")
        else:
            print("余额不足，无法购买。")
    else:
        print("不存在此商品，请再看看吧。")
    return budget

products = {'F00001':{'name':'苹果', 'price':1.2},
            'F00002':{'name':'香蕉', 'price':5.5}}

def sanle_system():
    username = input("请输入你的用户名:")
    passwd = input("请输入你的密码:")
    if login(username, passwd):
        budget =float(input("请输入你的购物预算:"))
        Budget(budget)
    else:
        print("登录失败")
        return

    checkProduct()

    while True:
        #选择操作
        action = input("请输入操作：\n1:查看商品信息 \n2：查看已购买商品信息 \n3:购买商品\nexit:退出系统 \n请选择你的操作:")
        if action == '1':
            checkProduct()
        elif action == '2':
            viewPurchased()
        elif action == '3':
            products_id = input("请输入要购买的商品编号:")
            budget = buy_product(products_id, budget)
        elif action == 'exit':
            print(f"已退出系统，您的余额为:{budget}")
            break



sanle_system()